<?php
/**
 * 产品分类文件
 *
 * @author		Arthur(ArthurXF@gmail.com)
 * @copyright	(c) 2006 by bizeway.com
 * @version		$Id$
 * @package		ArthurXF
 * @subpackage	product
 */
if (is_object($objWebInit)) {
	if(!isset($objproduct)){
		include_once(__WEB_ROOT."/product/class/product.class.php");
		include_once(__WEB_ROOT."/product/config/var.inc.php");
		$objproduct = new product();
		$objproduct->setDBG($arrGPdoDB);
		if(is_object($objWebInit->db)) $objproduct->db = $objWebInit->db;
		else $objproduct->db();
	}

	if(empty($_GET['type_id'])){
		$arrChildType = $objproduct->getTypeTileWithBrand("where t2.brand_id = '$_GET[brand_id]'",' ORDER BY initial');
		$arrMOutput["smarty_assign"]['arrChildType'] = $arrChildType;
	}else{
		$type_id = intval($_GET['type_id']);
		$arrChildType = $objproduct->getTypeList("where (type_parentid = $type_id or type_id = $type_id) and type_parentid != 0 and type_pass=1",' order by initial,type_sort desc');

		//======================================
		$arrMOutput["smarty_assign"]['strMenuTypeTitle'] = $arrMOutput["smarty_assign"]['strTypeTitle'];
		if(empty($arrChildType)&&!empty($arrTypeInfo['type_parentid'])){
			$arrChildType =  $objproduct->getTypeList("where type_parentid = $arrTypeInfo[type_parentid] and type_pass=1",' order by initial,type_sort desc');
			if(is_array($arrMType)&&!empty($arrMType)){
				$arrMOutput["smarty_assign"]['strTypeTitle'] = $arrMType[$intTypeID];
			}else{
				$arrTypeTemp = $objWebInit->getTypeInfo($arrTypeInfo['type_parentid']);
				$arrMOutput["smarty_assign"]['strMenuTypeTitle'] = $arrTypeTemp['type_title'];
			}

		}

		//=======统计产品子类的个数================
		$strProductIds = '';
		$arrProductTypeNums = array();

		if(!empty($arrChildType)){
			foreach($arrChildType as $k=>$v){
				$strProductIds .= $strProductIds === '' ? "where type_roue_id LIKE '%:".$v['type_id'].":%'" : " or type_roue_id LIKE '%:".$v['type_id'].":%'";
				$arrChildType[$k]['nums'] = 0;
			}

			//品牌brand_id
			if(!empty($_GET['brand_id']) && $_GET['brand_id'] != 'all'){
				$strWhere .= ' and brand_id='.$_GET['brand_id'];
			}

			$arrProductTypeNums = $objWebInit->getInfoList($strWhere,'',0,0,'type_roue_id');
			unset($arrProductTypeNums['COUNT_ROWS']);

			//替换数据
			if(!empty($arrProductTypeNums)){
				foreach($arrChildType as $k=>$v){
					foreach($arrProductTypeNums as $k1=>$v1){
						if(strpos($v1['type_roue_id'],$v['type_roue_id']) !== false ){
							$arrChildType[$k]['nums'] = $arrChildType[$k]['nums'] + 1;
						}
					}
				}
			}
		}

		//=====================================
		// 输出到模板
		$arrMOutput["smarty_assign"]['arrChildType'] = $arrChildType;
		$arrMOutput["smarty_assign"]['arrProductTypeNums'] = $arrProductTypeNums;
	}

}
?>